package dk.au.cs.peterbn.processing;

import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;

import java.net.URL;
import java.util.Set;

/**
 * Factory for the reflections class.
 *
 * Primary motivation for this is the ability to avoid instantiating the reflections for every test.
 */
public class ReflectionsFactory {
    public Reflections getReflections(CompilerOptions compilerOptions) {
        Set<URL> urls;
        if (compilerOptions != null) {
            urls = compilerOptions.getPatternLookupUrls();
        } else {
            urls = ClasspathHelper.forJavaClassPath();
        }
        return new Reflections(
                new ConfigurationBuilder()
                        .setUrls(urls).useParallelExecutor().filterInputsBy(new FilterBuilder().exclude("com.ibm.icu.impl.data.*"))
                        .setScanners(new TypeAnnotationsScanner(),
                                new MethodAnnotationsScanner()));                                                              
    }
}
